<?php require '../public/system/headers/headers.php';?>
<?php $this->headScript()->appendFile($this->websiteUrl .'system/js/jquery/jquery.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl .'system/js/jquery/jquery.qtip.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl .'system/js/php.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl .'system/js/shipping/shipping.js'); ?>
<?php //echo $this->headScript(); ?>
<!--?php echo $this->headLink()->appendStylesheet($this->websiteUrl . 'system/css/seotoaster.css'); ?-->
<div id="seotoaster" class="cartview">
	<div id="startmsg" class="success" style="display: none; position: fixed">
		Updating your cart. Please wait...
	</div>
	<div id="companyinfo">
		<img src="<?php echo str_replace('/small/', '/original/',$this->logoPath . $this->companyLogoName); ?>" alt="<?php echo $this->companyName; ?>" />
		<div>
                    <p><?php echo $this->config['company']; ?><p>
                    <p><?php echo $this->config['address'];
                    if (!empty($this->config['address']) && !empty($this->config['address2'])) echo ', ';
                    if (!empty($this->config['address2'])) echo $this->config['address2'];
                    ?></p>
                    <p><?php
                    if (!empty($this->config['city'])) echo $this->config['city'];
                    if (!empty($this->config['city']) && (!empty($this->config['state']) or !empty($this->config['zip']))) echo ', ';
                    if (!empty($this->config['state'])) echo $this->config['state'];
                    if (!empty($this->config['state']) && !empty($this->config['zip'])) echo ' ';
                    if (!empty($this->config['zip'])) echo $this->config['zip'];
                    ?></p>
                <p><?php if (!empty($this->config['country'])) echo $this->config['country']; ?></p>
                <p><?php echo $this->config['phone'];?></p>
                <p><a href="mailto:<?php echo $this->config['email']; ?>"><?php echo $this->config['email']; ?></a></p>
		</div>
		<h1 style="text-align:center;position:absolute;bottom:5px;right:15px;">{%Shopping cart overview%}</h1>
	</div>

	<div id="cartview-toplegend">
		<div style="width:28%;">{%Photo%}</div>
		<div style="width:32%;">{%Description%}</div>
		<div style="width:10%;">{%Amount%}</div>
		<div style="width:10%;">{%Price%}</div>
		<div style="width:10%;" id="tax-head">{%Tax%} *</div>
		<div style="width:10%;">{%Remove%}</div>
	</div>
    <?php $paypalDescriptionProducts= ''; $paypalItemIdProducts = ''; ?>

		<form action="javascript:;" id="cartview-itemsholder">
			<?php foreach($this->products as $key => $product): ?>
			  <div class="productitem" id="item-<?php echo $product['id'] . '-' . $key; ?>">
					<div class="item-photo" style="width:28%;"><img src="<?php echo $this->websiteUrl . $product['photo']; ?>" alt="<?php echo $product['name']; ?>"/></div>
					<div class="item-name" style="width:32%;text-align:left;"><?php echo substr($product['name'],0,50); ?>
						<?php if(isset($product['options'])): ?>
							<?php foreach($product['options'] as $optKey => $optionsData): ?>
								<?php if($optionsData != 'select ' . $optKey): echo $optKey . ': ' . $optionsData; endif;?>
								<input class="<?php echo $product['id'] . '-' . $key; ?>" type="hidden" value="<?php echo $optKey . '=' . $optionsData; ?>" />
							<?php endforeach; ?>
						<?php endif; ?>
					</div>
					<div class="item-count" style="width:10%;"><input  onchange="//javascript: recountOrder();" name="itemsCount[<?php echo $product['id'] ?>]" type="text" id="itmcount-<?php echo $product['id'] . '-' . $key; ?>" value="<?php echo $product['count']; ?>" /></div>
					<div class="item-price" style="width:10%;font-weight:bold;"><?php echo $product['price']; ?></div>
					<div class="item-tax" style="width:10%;font-weight:bold;">-</div>
					<div class="item-delchck" style="width:10%;"><input type="checkbox" id="todelete-<?php echo $product['id'] . '-' . $key; ?>"/></div>
				</div> <?php $paypalDescriptionProducts .= $product['name'].'('.$product['itemId'].', '.$product['count'].'), '; $paypalItemIdProducts .= $product['itemId'].','; ?>
			<?php endforeach; ?>
		</form>

    <?php if ($this->allowShipping && $this->total > 0): ?>
    <div id="shipping-info">
        <div id="shipping-info-title" >
            <span>{%Enter your shipping address%}</span>
            <input  type="button" id="edit-shipping" class="formsubmit" style="margin-left: 20px; width: 80px  ;" onclick="$('#shipping-info-form').show();" value="{%Edit%}"/>
        </div>
        <form id="shipping-info-form" action="javascript:;">
            <div>
                <p><label>{%First Name%}: *</label> <input type="text" name="shipping-firstname" id="shipping-firstname" value="<?php echo $this->shippingData['firstname'];?>"></p>
                <p><label>{%Last Name%}:</label> <input type="text" name="shipping-lastname" id="shipping-lastname" value="<?php echo $this->shippingData['lastname'];?>"></p>
                <p><label>{%E-mail%}:</label> <input type="text" name="shipping-email" id="shipping-email" value="<?php echo $this->shippingData['email'];?>"></p>
                <p><label>{%Shipping Address%} 1: *</label> <input type="text" name="shipping-address1" id="shipping-address1" value="<?php echo $this->shippingData['address1'];?>"></p>
                <p><label>{%Shipping Address%} 2:</label> <input type="text" name="shipping-address2" id="shipping-address2" value="<?php echo $this->shippingData['address2'];?>"></p>
            </div>
            <div>
                <p><label>{%Country%}: *</label>
                <select id="shipping-country" name="shipping-country">
                    <option value=""></option>
                    <option value="US">United States</option>
                    <option value="AL">Albania</option>
                    <option value="DZ">Algeria</option>
                    <option value="AD">Andorra</option>
                    <option value="AO">Angola</option>
                    <option value="AI">Anguilla</option>
                    <option value="AG">Antigua and Barbuda</option>
                    <option value="AR">Argentina</option>
                    <option value="AM">Armenia</option>
                    <option value="AW">Aruba</option>
                    <option value="AU">Australia</option>
                    <option value="AT">Austria</option>
                    <option value="AZ">Azerbaijan Republic</option>
                    <option value="BS">Bahamas</option>
                    <option value="BH">Bahrain</option>
                    <option value="BB">Barbados</option>
                    <option value="BE">Belgium</option>
                    <option value="BZ">Belize</option>
                    <option value="BJ">Benin</option>
                    <option value="BM">Bermuda</option>
                    <option value="BT">Bhutan</option>
                    <option value="BO">Bolivia</option>
                    <option value="BA">Bosnia and Herzegovina</option>
                    <option value="BW">Botswana</option>
                    <option value="BR">Brazil</option>
                    <option value="VG">British Virgin Islands</option>
                    <option value="BN">Brunei</option>
                    <option value="BG">Bulgaria</option>
                    <option value="BF">Burkina Faso</option>
                    <option value="BI">Burundi</option>
                    <option value="KH">Cambodia</option>
                    <option value="CA">Canada</option>
                    <option value="CV">Cape Verde</option>
                    <option value="KY">Cayman Islands</option>
                    <option value="TD">Chad</option>
                    <option value="CL">Chile</option>
                    <option value="C2">China</option>
                    <option value="CO">Colombia</option>
                    <option value="KM">Comoros</option>
                    <option value="CK">Cook Islands</option>
                    <option value="CR">Costa Rica</option>
                    <option value="HR">Croatia</option>
                    <option value="CY">Cyprus</option>
                    <option value="CZ">Czech Republic</option>
                    <option value="CD">Democratic Republic of the Congo</option>
                    <option value="DK">Denmark</option>
                    <option value="DJ">Djibouti</option>
                    <option value="DM">Dominica</option>
                    <option value="DO">Dominican Republic</option>
                    <option value="EC">Ecuador</option>
                    <option value="SV">El Salvador</option>
                    <option value="ER">Eritrea</option>
                    <option value="EE">Estonia</option>
                    <option value="ET">Ethiopia</option>
                    <option value="FK">Falkland Islands</option>
                    <option value="FO">Faroe Islands</option>
                    <option value="FM">Federated States of Micronesia</option>
                    <option value="FJ">Fiji</option>
                    <option value="FI">Finland</option>
                    <option value="FR">France</option>
                    <option value="GF">French Guiana</option>
                    <option value="PF">French Polynesia</option>
                    <option value="GA">Gabon Republic</option>
                    <option value="GM">Gambia</option>
                    <option value="DE">Germany</option>
                    <option value="GI">Gibraltar</option>
                    <option value="GR">Greece</option>
                    <option value="GL">Greenland</option>
                    <option value="GD">Grenada</option>
                    <option value="GP">Guadeloupe</option>
                    <option value="GT">Guatemala</option>
                    <option value="GN">Guinea</option>
                    <option value="GW">Guinea Bissau</option>
                    <option value="GY">Guyana</option>
                    <option value="HN">Honduras</option>
                    <option value="HK">Hong Kong</option>
                    <option value="HU">Hungary</option>
                    <option value="IS">Iceland</option>
                    <option value="IN">India</option>
                    <option value="ID">Indonesia</option>
                    <option value="IE">Ireland</option>
                    <option value="IL">Israel</option>
                    <option value="IT">Italy</option>
                    <option value="JM">Jamaica</option>
                    <option value="JP">Japan</option>
                    <option value="JO">Jordan</option>
                    <option value="KZ">Kazakhstan</option>
                    <option value="KE">Kenya</option>
                    <option value="KI">Kiribati</option>
                    <option value="KW">Kuwait</option>
                    <option value="KG">Kyrgyzstan</option>
                    <option value="LA">Laos</option>
                    <option value="LV">Latvia</option>
                    <option value="LS">Lesotho</option>
                    <option value="LI">Liechtenstein</option>
                    <option value="LT">Lithuania</option>
                    <option value="LU">Luxembourg</option>
                    <option value="MG">Madagascar</option>
                    <option value="MW">Malawi</option>
                    <option value="MY">Malaysia</option>
                    <option value="MV">Maldives</option>
                    <option value="ML">Mali</option>
                    <option value="MT">Malta</option>
                    <option value="MH">Marshall Islands</option>
                    <option value="MQ">Martinique</option>
                    <option value="MR">Mauritania</option>
                    <option value="MU">Mauritius</option>
                    <option value="YT">Mayotte</option>
                    <option value="MX">Mexico</option>
                    <option value="MN">Mongolia</option>
                    <option value="MS">Montserrat</option>
                    <option value="MA">Morocco</option>
                    <option value="MZ">Mozambique</option>
                    <option value="NA">Namibia</option>
                    <option value="NR">Nauru</option>
                    <option value="NP">Nepal</option>
                    <option value="NL">Netherlands</option>
                    <option value="AN">Netherlands Antilles</option>
                    <option value="NC">New Caledonia</option>
                    <option value="NZ">New Zealand</option>
                    <option value="NI">Nicaragua</option>
                    <option value="NE">Niger</option>
                    <option value="NU">Niue</option>
                    <option value="NF">Norfolk Island</option>
                    <option value="NO">Norway</option>
                    <option value="OM">Oman</option>
                    <option value="PW">Palau</option>
                    <option value="PA">Panama</option>
                    <option value="PG">Papua New Guinea</option>
                    <option value="PE">Peru</option>
                    <option value="PH">Philippines</option>
                    <option value="PN">Pitcairn Islands</option>
                    <option value="PL">Poland</option>
                    <option value="PT">Portugal</option>
                    <option value="QA">Qatar</option>
                    <option value="CG">Republic of the Congo</option>
                    <option value="RE">Reunion</option>
                    <option value="RO">Romania</option>
                    <option value="RU">Russia</option>
                    <option value="RW">Rwanda</option>
                    <option value="VC">Saint Vincent and the Grenadines</option>
                    <option value="WS">Samoa</option>
                    <option value="SM">San Marino</option>
                    <option value="ST">São Tomé and Príncipe</option>
                    <option value="SA">Saudi Arabia</option>
                    <option value="SN">Senegal</option>
                    <option value="SC">Seychelles</option>
                    <option value="SL">Sierra Leone</option>
                    <option value="SG">Singapore</option>
                    <option value="SK">Slovakia</option>
                    <option value="SI">Slovenia</option>
                    <option value="SB">Solomon Islands</option>
                    <option value="SO">Somalia</option>
                    <option value="ZA">South Africa</option>
                    <option value="KR">South Korea</option>
                    <option value="ES">Spain</option>
                    <option value="LK">Sri Lanka</option>
                    <option value="SH">St. Helena</option>
                    <option value="KN">St. Kitts and Nevis</option>
                    <option value="LC">St. Lucia</option>
                    <option value="PM">St. Pierre and Miquelon</option>
                    <option value="SR">Suriname</option>
                    <option value="SJ">Svalbard and Jan Mayen Islands</option>
                    <option value="SZ">Swaziland</option>
                    <option value="SE">Sweden</option>
                    <option value="CH">Switzerland</option>
                    <option value="TW">Taiwan</option>
                    <option value="TJ">Tajikistan</option>
                    <option value="TZ">Tanzania</option>
                    <option value="TH">Thailand</option>
                    <option value="TG">Togo</option>
                    <option value="TO">Tonga</option>
                    <option value="TT">Trinidad and Tobago</option>
                    <option value="TN">Tunisia</option>
                    <option value="TR">Turkey</option>
                    <option value="TM">Turkmenistan</option>
                    <option value="TC">Turks and Caicos Islands</option>
                    <option value="TV">Tuvalu</option>
                    <option value="UG">Uganda</option>
                    <option value="UA">Ukraine</option>
                    <option value="AE">United Arab Emirates</option>
                    <option value="GB">United Kingdom</option>
                    <option value="UY">Uruguay</option>
                    <option value="VU">Vanuatu</option>
                    <option value="VA">Vatican City State</option>
                    <option value="VE">Venezuela</option>
                    <option value="VN">Vietnam</option>
                    <option value="WF">Wallis and Futuna Islands</option>
                    <option value="YE">Yemen</option>
                    <option value="ZM">Zambia</option>
                </select>
            </p>
                <p><label>{%City%}: *</label> <input type="text" name="shipping-city" id="shipping-city" value="<?php echo $this->shippingData['city'];?>"></p>
                <p><label>{%State%}:</label>
                <select id="shipping-state" name="shipping-state" <?php echo (empty($this->shippingData['state'])? 'disabled="true"' : ' ') ?> >
                    <option value="" />
                </select>
            </p>
            <p><label>{%ZIP Code%}: *</label><input type="text" name="shipping-zip" id="shipping-zip"  value="<?php echo $this->shippingData['zip'];?>"></p>
            
            <p><label>{%Phone%}:</label><input type="text" name="shipping-phone" id="shipping-phone"  value="<?php echo $this->shippingData['phone'];?>"></p>
            </div>
            <?php if ($this->shippingGeneral['gifting'] == 'on') : ?>
            <div>
                <p><input type="checkbox" name="gift-order" id="gift-order"/><label>{%This order is a gift. (Gift orders will not ship with a receipt)%}</label></p>
                <textarea rows="3" name="gift-card-message" id="gift-cart-message" style="width:97%;" onfocus="if(this.value=='{%Enter Your Gift Card Message Here%}...'){this.value='';}" onblur="if(this.value==''){this.value='{%Enter Your Gift Card Message Here%}...';}">{%Enter Your Gift Card Message Here%}...</textarea>
            </div>
            <?php endif; ?>
        </form>
    </div><!--shipping info-->
    <?php endif; ?>
    <?php $paypalDescriptionProducts = rtrim($paypalDescriptionProducts, ', '); $paypalItemIdProducts = rtrim($paypalItemIdProducts, ','); ?>
    
    <div id="totalprice">
    	<button class="formsubmit" id="keepshopping" onclick="window.location.href='<?php echo $this->keepShoppingUrl; ?>';" style="float:left;">{%Keep shopping%}</button>
        <?php if ($this->total > 0) : ?>
            <?php if ($this->allowShipping) : ?>
            <button class="formsubmit" id="checkout" onclick="countTaxes();validateShippingForm();" style="float:left;margin-left:20px;">{%Calculate shipping and checkout%}</button>
            <?php else :?>
            <button class="formsubmit" id="checkout" onclick="$('.cart-pay').show('slow');" style="float:left;margin-left:20px;">{%Checkout%}</button>
            <?php endif;?>
            <button class="formsubmit" id="recount" onclick="recountOrder();"  style="float:left;margin-left:20px;">{%Update cart%} >>></button><?php endif; ?><br />
            <?php if (trim($this->shippingGeneral['notice'])!=''):?>
            <div style="float:left; clear: left; width: 500px">
                <?php echo $this->shippingGeneral['notice']; ?>
            </div>
            <?php endif; ?>
                <div>
                    <span>{%Sub Total%}:</span>&nbsp;<?php if ($this->total):?><span style="float:right; margin:0px 5px"><?php echo $this->currency;?></span><? endif; ?><span id="sub-total" style="float:right"><?php echo ($this->total) ? number_format($this->total,2,'.','')  : '{%There are no items in your cart.%}'; ?></span><br/>
                    <span>{%Total Tax%}:</span>&nbsp;<span style="float:right; margin:0px 5px"><?php echo $this->currency;?></span><span id="total-tax" style="float:right"><?php echo ($this->totalTax) ? $this->totalTax : ''; ?></span><br/>
                    <span>{%Shipping%}:</span>&nbsp;<span style="float:right; margin:0px 5px"><?php echo $this->currency;?></span><span id="shipping-value" style="float:right"><?php echo ($this->shipping) ? $this->shipping : ''; ?></span><br/>
                    <span>{%Total%}:</span>&nbsp;<span style="float:right; margin:0px 5px"><?php echo $this->currency;?></span><span id="total-price-value" style="float:right"><?php echo ($this->totalPrice) ? $this->totalPrice : ''; ?></span>
		</div>
    </div>

<div style="padding-top:4px;"></div>
    <div class="cart-pay">
    	<div style="padding-top:1px;"></div>
        <!--div class="cart-pay-title">{%Pay with PayPal%}:</div>
        <div id="cart-paypal-account"><span>+</span> {%Account%}</div-->
        <fieldset id="cart-settings-paypal-account" class="cart-settings" style="text-align:center;margin-top:15px;"><legend style="float:left;">{%Pay with PayPal%} {%Account%}</legend>
            <form action="https://www.paypal.com/cgi-bin/webscr" target="_blank" method="post">
                <input type="hidden" name="cmd" value="_xclick">
                <input type="hidden" name="business" value="<?php echo $this->settingsPayPal['email']; ?>">
                <input type="hidden" name="lc" value="US">
                <input type="hidden" name="item_name" value="<?php echo $paypalDescriptionProducts; ?>">
                <input type="hidden" name="item_number" value="<?php echo $paypalItemIdProducts; ?>">
                <input type="hidden" name="amount" value="<?php echo $this->total; ?>">
                <input type="hidden" name="shipping" value="<?php echo $this->shipping; ?>">
                <input type="hidden" name="tax" value="<?php echo ($this->totalTax) ? $this->totalTax : '0'; ?>">
                <input type="hidden" name="currency_code" value="<?php echo $this->config['currency']; ?>">
                <input type="hidden" name="button_subtype" value="products">
                <input type="hidden" name="notify_url" value="<?php echo $this->websiteUrl; ?>sys/backend_shopping/handlerpaypalaccount/">
                <input type="hidden" name="rm"  value="2">
                <input type="hidden" name="cancel_return" value="<?php echo $this->websiteUrl; ?>cart">
                <input type="hidden" name="bn" value="PP-BuyNowBF:btn_paynow_LG.gif:NonHostedGuest">
                <input type="image" src="<?php echo $this->websiteUrl; ?>system/images/btn_paynow_LG.gif" border="0" name="submit" alt="PayPal" style="padding:0;border:0;">
             </form>
        </fieldset>
        <?php if (!empty($this->settingsPayPal['user']) && !empty($this->settingsPayPal['signature'])): ?>
        <div class="cart-pay-title">{%OR%}</div>
        <!--div id="cart-credit-card"><span>+</span> {%Credit Cart%}</div-->
        <fieldset style="margin-top:15px;" id="cart-settings-credit-card" class="cart-settings"><legend>{%Credit Card%}</legend>
            <form action="javascript:;" name="paypal-creditcard" id="paypal-creditcard">
                <fieldset style="width:50%;float:left;margin-right:20px;">
                <p><label>{%First Name%}:</label> <input type="text" name="credit-card-firstname" id="credit-card-firstname"></p>
                <p><label>{%Last Name%}:</label> <input type="text" name="credit-card-lastname" id="credit-card-lastname"></p>
                <p><label>{%Payment Type%}:</label>
                    <select name="credit-card-type" id="credit-card-type">
                        <option value="Visa" selected="selected">Visa</option>
                        <option value="MasterCard">MasterCard</option>
                        <option value="Discover">Discover</option>
                        <option value="Amex">American Express</option>
                    </select>
                </p>
                <p><label>{%Credit Card Number%}:</label> <input type="text" name="credit-card-cardnumber" id="credit-card-cardnumber"></p>
                <p><label>{%Card Verification Number%}:</label> <input type="text" name="credit-card-verification-number" id="credit-card-verification-number"></p>
                <p><label>{%Expiration Date%}:</label>
                    <select name="credit-card-expiration-date-year" id="credit-card-expiration-date-year" style="width:100px;margin-left:5px;">
                        <?php $currentYear = date('Y'); ?>
                        <?php for ($y=$currentYear; $y<=$currentYear+10; $y++): ?>
                        <option value="<?php echo $y; ?>"><?php echo $y; ?></option>
                        <?php endfor; ?>
                    </select>
                       <select name="credit-card-expiration-date-month" id="credit-card-expiration-date-month" style="width:50px;">
                        <?php for ($m=1; $m<=12; $m++) : ?>
                        <option value="<?php echo $m; ?>"><?php echo $m; ?></option>
                        <?php endfor; ?>
                    </select>
                </p>
                <p><label>{%E-mail%}:</label> <input type="text" name="credit-card-email" id="credit-card-email"></p>
                </fieldset>
				<fieldset>
                <p><label>{%Billing Address%} 1:</label> <input type="text" name="credit-card-billing-address1" id="credit-card-billing-address1"></p>
                <p><label>{%Billing Address%} 2:</label> <input type="text" name="credit-card-billing-address2" id="credit-card-billing-address2"></p>
                <p><label>{%Country%}:</label>
                    <select id="credit-card-country" name="credit-card-country">
                        <option value=""></option>
                        <option value="US">United States</option>
                        <option value="AL">Albania</option>
                        <option value="DZ">Algeria</option>
                        <option value="AD">Andorra</option>
                        <option value="AO">Angola</option>
                        <option value="AI">Anguilla</option>
                        <option value="AG">Antigua and Barbuda</option>
                        <option value="AR">Argentina</option>
                        <option value="AM">Armenia</option>
                        <option value="AW">Aruba</option>
                        <option value="AU">Australia</option>
                        <option value="AT">Austria</option>
                        <option value="AZ">Azerbaijan Republic</option>
                        <option value="BS">Bahamas</option>
                        <option value="BH">Bahrain</option>
                        <option value="BB">Barbados</option>
                        <option value="BE">Belgium</option>
                        <option value="BZ">Belize</option>
                        <option value="BJ">Benin</option>
                        <option value="BM">Bermuda</option>
                        <option value="BT">Bhutan</option>
                        <option value="BO">Bolivia</option>
                        <option value="BA">Bosnia and Herzegovina</option>
                        <option value="BW">Botswana</option>
                        <option value="BR">Brazil</option>
                        <option value="VG">British Virgin Islands</option>
                        <option value="BN">Brunei</option>
                        <option value="BG">Bulgaria</option>
                        <option value="BF">Burkina Faso</option>
                        <option value="BI">Burundi</option>
                        <option value="KH">Cambodia</option>
                        <option value="CA">Canada</option>
                        <option value="CV">Cape Verde</option>
                        <option value="KY">Cayman Islands</option>
                        <option value="TD">Chad</option>
                        <option value="CL">Chile</option>
                        <option value="C2">China</option>
                        <option value="CO">Colombia</option>
                        <option value="KM">Comoros</option>
                        <option value="CK">Cook Islands</option>
                        <option value="CR">Costa Rica</option>
                        <option value="HR">Croatia</option>
                        <option value="CY">Cyprus</option>
                        <option value="CZ">Czech Republic</option>
                        <option value="CD">Democratic Republic of the Congo</option>
                        <option value="DK">Denmark</option>
                        <option value="DJ">Djibouti</option>
                        <option value="DM">Dominica</option>
                        <option value="DO">Dominican Republic</option>
                        <option value="EC">Ecuador</option>
                        <option value="SV">El Salvador</option>
                        <option value="ER">Eritrea</option>
                        <option value="EE">Estonia</option>
                        <option value="ET">Ethiopia</option>
                        <option value="FK">Falkland Islands</option>
                        <option value="FO">Faroe Islands</option>
                        <option value="FM">Federated States of Micronesia</option>
                        <option value="FJ">Fiji</option>
                        <option value="FI">Finland</option>
                        <option value="FR">France</option>
                        <option value="GF">French Guiana</option>
                        <option value="PF">French Polynesia</option>
                        <option value="GA">Gabon Republic</option>
                        <option value="GM">Gambia</option>
                        <option value="DE">Germany</option>
                        <option value="GI">Gibraltar</option>
                        <option value="GR">Greece</option>
                        <option value="GL">Greenland</option>
                        <option value="GD">Grenada</option>
                        <option value="GP">Guadeloupe</option>
                        <option value="GT">Guatemala</option>
                        <option value="GN">Guinea</option>
                        <option value="GW">Guinea Bissau</option>
                        <option value="GY">Guyana</option>
                        <option value="HN">Honduras</option>
                        <option value="HK">Hong Kong</option>
                        <option value="HU">Hungary</option>
                        <option value="IS">Iceland</option>
                        <option value="IN">India</option>
                        <option value="ID">Indonesia</option>
                        <option value="IE">Ireland</option>
                        <option value="IL">Israel</option>
                        <option value="IT">Italy</option>
                        <option value="JM">Jamaica</option>
                        <option value="JP">Japan</option>
                        <option value="JO">Jordan</option>
                        <option value="KZ">Kazakhstan</option>
                        <option value="KE">Kenya</option>
                        <option value="KI">Kiribati</option>
                        <option value="KW">Kuwait</option>
                        <option value="KG">Kyrgyzstan</option>
                        <option value="LA">Laos</option>
                        <option value="LV">Latvia</option>
                        <option value="LS">Lesotho</option>
                        <option value="LI">Liechtenstein</option>
                        <option value="LT">Lithuania</option>
                        <option value="LU">Luxembourg</option>
                        <option value="MG">Madagascar</option>
                        <option value="MW">Malawi</option>
                        <option value="MY">Malaysia</option>
                        <option value="MV">Maldives</option>
                        <option value="ML">Mali</option>
                        <option value="MT">Malta</option>
                        <option value="MH">Marshall Islands</option>
                        <option value="MQ">Martinique</option>
                        <option value="MR">Mauritania</option>
                        <option value="MU">Mauritius</option>
                        <option value="YT">Mayotte</option>
                        <option value="MX">Mexico</option>
                        <option value="MN">Mongolia</option>
                        <option value="MS">Montserrat</option>
                        <option value="MA">Morocco</option>
                        <option value="MZ">Mozambique</option>
                        <option value="NA">Namibia</option>
                        <option value="NR">Nauru</option>
                        <option value="NP">Nepal</option>
                        <option value="NL">Netherlands</option>
                        <option value="AN">Netherlands Antilles</option>
                        <option value="NC">New Caledonia</option>
                        <option value="NZ">New Zealand</option>
                        <option value="NI">Nicaragua</option>
                        <option value="NE">Niger</option>
                        <option value="NU">Niue</option>
                        <option value="NF">Norfolk Island</option>
                        <option value="NO">Norway</option>
                        <option value="OM">Oman</option>
                        <option value="PW">Palau</option>
                        <option value="PA">Panama</option>
                        <option value="PG">Papua New Guinea</option>
                        <option value="PE">Peru</option>
                        <option value="PH">Philippines</option>
                        <option value="PN">Pitcairn Islands</option>
                        <option value="PL">Poland</option>
                        <option value="PT">Portugal</option>
                        <option value="QA">Qatar</option>
                        <option value="CG">Republic of the Congo</option>
                        <option value="RE">Reunion</option>
                        <option value="RO">Romania</option>
                        <option value="RU">Russia</option>
                        <option value="RW">Rwanda</option>
                        <option value="VC">Saint Vincent and the Grenadines</option>
                        <option value="WS">Samoa</option>
                        <option value="SM">San Marino</option>
                        <option value="ST">São Tomé and Príncipe</option>
                        <option value="SA">Saudi Arabia</option>
                        <option value="SN">Senegal</option>
                        <option value="SC">Seychelles</option>
                        <option value="SL">Sierra Leone</option>
                        <option value="SG">Singapore</option>
                        <option value="SK">Slovakia</option>
                        <option value="SI">Slovenia</option>
                        <option value="SB">Solomon Islands</option>
                        <option value="SO">Somalia</option>
                        <option value="ZA">South Africa</option>
                        <option value="KR">South Korea</option>
                        <option value="ES">Spain</option>
                        <option value="LK">Sri Lanka</option>
                        <option value="SH">St. Helena</option>
                        <option value="KN">St. Kitts and Nevis</option>
                        <option value="LC">St. Lucia</option>
                        <option value="PM">St. Pierre and Miquelon</option>
                        <option value="SR">Suriname</option>
                        <option value="SJ">Svalbard and Jan Mayen Islands</option>
                        <option value="SZ">Swaziland</option>
                        <option value="SE">Sweden</option>
                        <option value="CH">Switzerland</option>
                        <option value="TW">Taiwan</option>
                        <option value="TJ">Tajikistan</option>
                        <option value="TZ">Tanzania</option>
                        <option value="TH">Thailand</option>
                        <option value="TG">Togo</option>
                        <option value="TO">Tonga</option>
                        <option value="TT">Trinidad and Tobago</option>
                        <option value="TN">Tunisia</option>
                        <option value="TR">Turkey</option>
                        <option value="TM">Turkmenistan</option>
                        <option value="TC">Turks and Caicos Islands</option>
                        <option value="TV">Tuvalu</option>
                        <option value="UG">Uganda</option>
                        <option value="UA">Ukraine</option>
                        <option value="AE">United Arab Emirates</option>
                        <option value="GB">United Kingdom</option>
                        <option value="UY">Uruguay</option>
                        <option value="VU">Vanuatu</option>
                        <option value="VA">Vatican City State</option>
                        <option value="VE">Venezuela</option>
                        <option value="VN">Vietnam</option>
                        <option value="WF">Wallis and Futuna Islands</option>
                        <option value="YE">Yemen</option>
                        <option value="ZM">Zambia</option>
                    </select>
                </p>
                <p><label>{%City%}:</label> <input type="text" name="credit-card-city" id="credit-card-city"></p>
                <p><label>{%State%}:</label>
                    <select id="credit-card-state" name="credit-card-state">
                        <option value="" />
                    </select>
                </p>
                <p><label>{%ZIP Code%}:</label><input type="text" name="credit-card-zip" id="credit-card-zip"></p>
                <p><label>{%Phone%}:</label><input type="text" name="credit-card-phone" id="credit-card-phone"></p>
                   <input type="hidden" name="credit-card-amt" id="credit-card-amt" value="<?php echo $this->total; ?>" />
                   <input type="hidden" name="credit-card-shipping" id="credit-card-shipping" value="<?php echo $this->shipping; ?>" />
                   <input type="hidden" name="credit-card-desc" id="credit-card-desc" value="<?php echo $paypalDescriptionProducts; ?>" />
                   <input type="hidden" name="credit-card-currency-code" id="credit-card-currency-code" value="<?php echo $this->config['currency']; ?>" />
                   <input type="hidden" name="credit-card-tax" id="credit-card-tax" value="<?php echo ($this->totalTax) ?  $this->totalTax : '0'; ?>" />
                </fieldset>
                <?php if ($this->allowShipping) : ?>
                <p align="right" style="margin:10px 15px 0px 0px;"><input type="checkbox" class="toggle-shipping" id="shipping-for-cc" style="margin: 2px 5px;"/><span>{%Use same address as shipping%}</span></p>
                <?php endif; ?>
                <p align="right" style="margin:10px 15px 0px 0px;"><input type="button" class="formsubmit" style="padding-left:15px;padding-right:15px;" name="credit-card-paynow" id="credit-card-paynow" value="{%Pay Now%}"  onclick="payCreditCart();"></p>
            </form>
        </fieldset>

        <?php endif; ?>
        <?php if ($this->config['quote']): ?>
        <div class="cart-pay-title">{%OR%} {%Generate Quote%}</div>

        <!--div id="cart-generate-quote"><span>+</span> {%Generate Quote%}</div-->
        <fieldset id="cart-settings-quote" class="cart-settings"><!--legend>{%Generate Quote%}</legend-->
            <form action="javascript:;" name="form_quote" id="form_quote">
                <fieldset style="width:50%;float:left;margin-right:20px;">
                    <p><label>{%Name%}:*</label><input type="text" name="cart-quote-name" id="cart-quote-name"></p>
                    <p><label>{%Company%}:</label><input type="text" name="cart-quote-company" id="cart-quote-company"></p>
                    <p><label>{%E-mail%}:*</label><input type="text" name="cart-quote-email" id="cart-quote-email"></p>
                    <p><label>{%Phone%}:</label><input type="text" name="cart-quote-phone" id="cart-quote-phone"></p>
                    <p><label>{%Address%} 1:</label><input type="text" name="cart-quote-address1" id="cart-quote-address1"></p>
                    <p><label>{%Address%} 2:</label><input type="text" name="cart-quote-address2" id="cart-quote-address2"></p></fieldset><fieldset>
                    <p><label>{%Country%}:</label>
                            <select id="cart-quote-country" name="cart-quote-country">
                                <option value=""></option>
                                <option value="US">United States</option>
                                <option value="AL">Albania</option>
                                <option value="DZ">Algeria</option>
                                <option value="AD">Andorra</option>
                                <option value="AO">Angola</option>
                                <option value="AI">Anguilla</option>
                                <option value="AG">Antigua and Barbuda</option>
                                <option value="AR">Argentina</option>
                                <option value="AM">Armenia</option>
                                <option value="AW">Aruba</option>
                                <option value="AU">Australia</option>
                                <option value="AT">Austria</option>
                                <option value="AZ">Azerbaijan Republic</option>
                                <option value="BS">Bahamas</option>
                                <option value="BH">Bahrain</option>
                                <option value="BB">Barbados</option>
                                <option value="BE">Belgium</option>
                                <option value="BZ">Belize</option>
                                <option value="BJ">Benin</option>
                                <option value="BM">Bermuda</option>
                                <option value="BT">Bhutan</option>
                                <option value="BO">Bolivia</option>
                                <option value="BA">Bosnia and Herzegovina</option>
                                <option value="BW">Botswana</option>
                                <option value="BR">Brazil</option>
                                <option value="VG">British Virgin Islands</option>
                                <option value="BN">Brunei</option>
                                <option value="BG">Bulgaria</option>
                                <option value="BF">Burkina Faso</option>
                                <option value="BI">Burundi</option>
                                <option value="KH">Cambodia</option>
                                <option value="CA">Canada</option>
                                <option value="CV">Cape Verde</option>
                                <option value="KY">Cayman Islands</option>
                                <option value="TD">Chad</option>
                                <option value="CL">Chile</option>
                                <option value="C2">China</option>
                                <option value="CO">Colombia</option>
                                <option value="KM">Comoros</option>
                                <option value="CK">Cook Islands</option>
                                <option value="CR">Costa Rica</option>
                                <option value="HR">Croatia</option>
                                <option value="CY">Cyprus</option>
                                <option value="CZ">Czech Republic</option>
                                <option value="CD">Democratic Republic of the Congo</option>
                                <option value="DK">Denmark</option>
                                <option value="DJ">Djibouti</option>
                                <option value="DM">Dominica</option>
                                <option value="DO">Dominican Republic</option>
                                <option value="EC">Ecuador</option>
                                <option value="SV">El Salvador</option>
                                <option value="ER">Eritrea</option>
                                <option value="EE">Estonia</option>
                                <option value="ET">Ethiopia</option>
                                <option value="FK">Falkland Islands</option>
                                <option value="FO">Faroe Islands</option>
                                <option value="FM">Federated States of Micronesia</option>
                                <option value="FJ">Fiji</option>
                                <option value="FI">Finland</option>
                                <option value="FR">France</option>
                                <option value="GF">French Guiana</option>
                                <option value="PF">French Polynesia</option>
                                <option value="GA">Gabon Republic</option>
                                <option value="GM">Gambia</option>
                                <option value="DE">Germany</option>
                                <option value="GI">Gibraltar</option>
                                <option value="GR">Greece</option>
                                <option value="GL">Greenland</option>
                                <option value="GD">Grenada</option>
                                <option value="GP">Guadeloupe</option>
                                <option value="GT">Guatemala</option>
                                <option value="GN">Guinea</option>
                                <option value="GW">Guinea Bissau</option>
                                <option value="GY">Guyana</option>
                                <option value="HN">Honduras</option>
                                <option value="HK">Hong Kong</option>
                                <option value="HU">Hungary</option>
                                <option value="IS">Iceland</option>
                                <option value="IN">India</option>
                                <option value="ID">Indonesia</option>
                                <option value="IE">Ireland</option>
                                <option value="IL">Israel</option>
                                <option value="IT">Italy</option>
                                <option value="JM">Jamaica</option>
                                <option value="JP">Japan</option>
                                <option value="JO">Jordan</option>
                                <option value="KZ">Kazakhstan</option>
                                <option value="KE">Kenya</option>
                                <option value="KI">Kiribati</option>
                                <option value="KW">Kuwait</option>
                                <option value="KG">Kyrgyzstan</option>
                                <option value="LA">Laos</option>
                                <option value="LV">Latvia</option>
                                <option value="LS">Lesotho</option>
                                <option value="LI">Liechtenstein</option>
                                <option value="LT">Lithuania</option>
                                <option value="LU">Luxembourg</option>
                                <option value="MG">Madagascar</option>
                                <option value="MW">Malawi</option>
                                <option value="MY">Malaysia</option>
                                <option value="MV">Maldives</option>
                                <option value="ML">Mali</option>
                                <option value="MT">Malta</option>
                                <option value="MH">Marshall Islands</option>
                                <option value="MQ">Martinique</option>
                                <option value="MR">Mauritania</option>
                                <option value="MU">Mauritius</option>
                                <option value="YT">Mayotte</option>
                                <option value="MX">Mexico</option>
                                <option value="MN">Mongolia</option>
                                <option value="MS">Montserrat</option>
                                <option value="MA">Morocco</option>
                                <option value="MZ">Mozambique</option>
                                <option value="NA">Namibia</option>
                                <option value="NR">Nauru</option>
                                <option value="NP">Nepal</option>
                                <option value="NL">Netherlands</option>
                                <option value="AN">Netherlands Antilles</option>
                                <option value="NC">New Caledonia</option>
                                <option value="NZ">New Zealand</option>
                                <option value="NI">Nicaragua</option>
                                <option value="NE">Niger</option>
                                <option value="NU">Niue</option>
                                <option value="NF">Norfolk Island</option>
                                <option value="NO">Norway</option>
                                <option value="OM">Oman</option>
                                <option value="PW">Palau</option>
                                <option value="PA">Panama</option>
                                <option value="PG">Papua New Guinea</option>
                                <option value="PE">Peru</option>
                                <option value="PH">Philippines</option>
                                <option value="PN">Pitcairn Islands</option>
                                <option value="PL">Poland</option>
                                <option value="PT">Portugal</option>
                                <option value="QA">Qatar</option>
                                <option value="CG">Republic of the Congo</option>
                                <option value="RE">Reunion</option>
                                <option value="RO">Romania</option>
                                <option value="RU">Russia</option>
                                <option value="RW">Rwanda</option>
                                <option value="VC">Saint Vincent and the Grenadines</option>
                                <option value="WS">Samoa</option>
                                <option value="SM">San Marino</option>
                                <option value="ST">São Tomé and Príncipe</option>
                                <option value="SA">Saudi Arabia</option>
                                <option value="SN">Senegal</option>
                                <option value="SC">Seychelles</option>
                                <option value="SL">Sierra Leone</option>
                                <option value="SG">Singapore</option>
                                <option value="SK">Slovakia</option>
                                <option value="SI">Slovenia</option>
                                <option value="SB">Solomon Islands</option>
                                <option value="SO">Somalia</option>
                                <option value="ZA">South Africa</option>
                                <option value="KR">South Korea</option>
                                <option value="ES">Spain</option>
                                <option value="LK">Sri Lanka</option>
                                <option value="SH">St. Helena</option>
                                <option value="KN">St. Kitts and Nevis</option>
                                <option value="LC">St. Lucia</option>
                                <option value="PM">St. Pierre and Miquelon</option>
                                <option value="SR">Suriname</option>
                                <option value="SJ">Svalbard and Jan Mayen Islands</option>
                                <option value="SZ">Swaziland</option>
                                <option value="SE">Sweden</option>
                                <option value="CH">Switzerland</option>
                                <option value="TW">Taiwan</option>
                                <option value="TJ">Tajikistan</option>
                                <option value="TZ">Tanzania</option>
                                <option value="TH">Thailand</option>
                                <option value="TG">Togo</option>
                                <option value="TO">Tonga</option>
                                <option value="TT">Trinidad and Tobago</option>
                                <option value="TN">Tunisia</option>
                                <option value="TR">Turkey</option>
                                <option value="TM">Turkmenistan</option>
                                <option value="TC">Turks and Caicos Islands</option>
                                <option value="TV">Tuvalu</option>
                                <option value="UG">Uganda</option>
                                <option value="UA">Ukraine</option>
                                <option value="AE">United Arab Emirates</option>
                                <option value="GB">United Kingdom</option>
                                <option value="UY">Uruguay</option>
                                <option value="VU">Vanuatu</option>
                                <option value="VA">Vatican City State</option>
                                <option value="VE">Venezuela</option>
                                <option value="VN">Vietnam</option>
                                <option value="WF">Wallis and Futuna Islands</option>
                                <option value="YE">Yemen</option>
                                <option value="ZM">Zambia</option>
                            </select>
                        </p>
                    <p><label>{%City%}:</label><input type="text" name="cart-quote-city" id="cart-quote-city"></p>
                    <p><label>{%State%}:</label>
                        <select id="cart-quote-state" name="cart-quote-state">
                            <option val="" />
                        </select>
                    </p>
                    <p><label>{%Zip%}:</label><input type="text" name="cart-quote-zip" id="cart-quote-zip"></p>

                    <p style="height:80px;"><label>{%Comments%}:</label><textarea name="cart-quote-comments" id="cart-quote-comments" cols="5" rows="3" style="width:200px;"></textarea></p>
                       </fieldset>
                <?php if ($this->allowShipping) : ?>
                <p align="right" style="margin:10px 15px 0px 0px;"><input type="checkbox" class="toggle-shipping" id="shipping-for-quote" style="margin: 2px 5px;"/><span>{%Use same address as shipping%}</span></p>
                <?php endif;?>
                <p align="right"><input type="button" class="formsubmit" name="cart-quote-quoteme" id="cart-quote-quoteme" value="{%Quote Me%}" style="padding-left:15px;padding-right:15px;" onclick="saveQuote();"></p>
            </form>
        </fieldset>
        <?php endif; ?>
        <br />
    </div>

</div>

<script type="text/javascript">

    $(document).ready(function(){

        //copying data from shipping address
        $(".toggle-shipping").click(function(){
           if ($(this).attr('checked') == true) {
               copyShippingData($(this).parent().parent().attr('name'));
               return;
           }
        })

        //adding tip for "Tax" column header
        $('#tax-head').qtip({
           content: 'Taxes will be recount according to shipping address',
           position: {
               corner: {
                 target: 'topMiddle',
                 tooltip: 'bottomMiddle'
               }
           },
           style: {
               tip: 'bottomMiddle',
               width: 200,
               padding: 5,
               name: 'light'
           },
           show: 'mouseover',
           hide: 'mouseout'
        })

        $('#shipping-state').closest('p').qtip({
           content: 'States only available for USA and Canada',
           position: {
               corner: {
                 target: 'rightMiddle',
                 tooltip: 'leftMiddle'
               }
           },
           style: {
               tip: 'leftMiddle',
               width: 200,
               padding: 5,
               name: 'light'
           },
           show: 'mouseover',
           hide: 'mouseout'
        })

        // load session based value
        $("#shipping-country").find("option[value='<?php echo $this->shippingData['country']?>']").attr('selected','selected');
        $("#shipping-state")
            .html(loadStates($("#shipping-country").val()))
            .find("option[value='<?php echo $this->shippingData['state']?>']").attr('selected','selected');

        // handler for changing country
        $("select[id$=country]").change(function(){
            var stateField = $(this).closest('form').find('select[id$=state]')
            
            if ($(this).val() == 'US' || $(this).val() == 'CA'){
                  stateField.removeAttr('disabled')
                  stateField.html(loadStates($(this).val()))
            } else {
                  stateField.attr('disabled',true)
                  stateField.html('')
            }

        });
        
        $("#edit-shipping").click(function(){
            $('#shipping-info-title span').text('Edit your shipping address');
            $('#current-shipping-address').remove();
            $('.cart-pay').hide();
            $('#checkout').show();
            $('#shipping-for-cc').attr('checked',false);
            $('#shipping-for-quote').attr('checked',false);
            $(this).hide();
        });
    });

    $('.productitem:odd').css('background', '#FFFFEE');
    document.getElementById('cart-paypal-account').addEventListener('click', function() {
        if (/[+]/g.test(this.childNodes.item(0).innerHTML)) {
            this.childNodes.item(0).innerHTML = '-';
            document.getElementById('cart-settings-paypal-account').style.display = 'block';
        } else {
            this.childNodes.item(0).innerHTML = '+';
            document.getElementById('cart-settings-paypal-account').style.display = 'none';
        }
    }, false);
     document.getElementById('cart-credit-card').addEventListener('click', function() {
        if (/[+]/g.test(this.childNodes.item(0).innerHTML)) {
            this.childNodes.item(0).innerHTML = '-';
            document.getElementById('cart-settings-credit-card').style.display = 'block';
        } else {
            this.childNodes.item(0).innerHTML = '+';
            document.getElementById('cart-settings-credit-card').style.display = 'none';
        }
    }, false);
     document.getElementById('cart-generate-quote').addEventListener('click', function(){
        if (/[+]/g.test(this.childNodes.item(0).innerHTML)) {
            this.childNodes.item(0).innerHTML = '-';
            document.getElementById('cart-settings-quote').style.display = 'block';
        } else {
            this.childNodes.item(0).innerHTML = '+';
            document.getElementById('cart-settings-quote').style.display = 'none';
        }
    }, false);
    
    function saveQuote()
    {
        var regEmail = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})$/;
        var name = $('#cart-quote-name').val();
        var email = $('#cart-quote-email').val();
        name = name.replace(/^\s+/g,''); name = name.replace(/\s+$/g,'');
        if(email == '' || !email.match(regEmail) || name == '') {
            return;
        }
        $.ajax({
            url : '<?php echo $this->websiteUrl; ?>sys/backend_shopping/quoteme/',
            type : 'post',
            dataType : 'json',
            data : {
                name : name,
                email : email,
                company : $('#cart-quote-company').val(),
                country : $('#cart-quote-country').val(),
                state : $('#cart-quote-state').val(),
                city : $('#cart-quote-city').val(),
                zip : $('#cart-quote-zip').val(),
                address1 : $('#cart-quote-address1').val(),
                address2 : $('#cart-quote-address2').val(),
                phone : $('#cart-quote-phone').val(),
                comments : $('#cart-quote-comments').val()
            },
            beforeSend : function() {
                $('#startmsg').html('Transmitting your quote request now...');
                $('#startmsg').show();
            },
            complete : function() {
                window.setTimeout('$("#startmsg").hide();', 3000);
            },
            success : function(result) {
                if (result.done) {
                    $('#startmsg').html('Your quote request was transmitted.');
                } else {
                    $('#startmsg').html('Your quote request is fail.');
                }
            }
        });
    }
    
    function payCreditCart()
    {
        $.ajax({
            url : '<?php echo $this->websiteUrl; ?>sys/backend_shopping/handlerpaypalcreditcard/',
            type : 'post',
            dataType : 'json',
            data : {
                firstname : $('#credit-card-firstname').val(),
                lastname : $('#credit-card-lastname').val(),
                type : $('#credit-card-type').val(),
                cardnumber : $('#credit-card-cardnumber').val(),
                verification_number : $('#credit-card-verification-number').val(),
                expiration_date_year : $('#credit-card-expiration-date-year').val(),
                expiration_date_month : $('#credit-card-expiration-date-month').val(),
                email: $('#credit-card-email').val(),
                billing_address1 : $('#credit-card-billing-address1').val(),
                billing_address2 : $('#credit-card-billing-address2').val(),
                city : $('#credit-card-city').val(),
                country : $('#credit-card-country').val(),
                state : $('#credit-card-state').val(),
                zip : $('#credit-card-zip').val(),
                phone : $('#credit-card-phone').val(),
                amt : $('#credit-card-amt').val(),
                desc : $('#credit-card-desc').val(),
                currency_code : $('#credit-card-currency-code').val(),
                tax : $('#credit-card-tax').val(),
                shipping : $('#credit-card-shipping').val()
            },
            beforeSend : function() {
                $('#startmsg').css('top', '70%');
                $('#startmsg').html('Process paying, please wait...');
                $('#startmsg').show();
            },
            complete : function() {
                window.setTimeout('$("#startmsg").hide(0, function() { $(this).css("top", "35%"); $(this).html("Updating your cart. Please wait...");});', 3000);
            },
            success : function(result) {
                if (result.done) {
                    $('#startmsg').html('You paid.');
                } else {
                    $('#startmsg').html('Sorry, your payment has failed, please double check your credit card information. If this error persists, please contact us.');
                }
            }
        });
    }

    function recountTotal(){
        var subTotal = (!isNaN($('#sub-total').text()) ? Number($('#sub-total').text()) : 0);
        var totalTax = (!isNaN($('#total-tax').text()) ? Number($('#total-tax').text()) : 0);
        var shipping = (!isNaN($('#shipping-value').text()) ? Number($('#shipping-value').text()) : 0);
        var total = subTotal + totalTax + shipping;
        //console.log(total);
        $('#total-price-value').text(total);
    }

    function countTaxes(){
        var urlwebsite = $('#hid-main-wsurl').val();

        var userCountry = $('#shipping-country').val();
        var userState   = $('#shipping-state').val();

        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: urlwebsite +'sys/backend_shopping/counttax/',
            data: ({
                userCountry: userCountry,
                userState: userState
            }),
            success: function(responce){
                //alert(responce.totaltax)
                $('#total-tax').text(responce.totaltax)
                $('#cart-settings-paypal-account').find('input:hidden[name=tax]').val(responce.totaltax)
                $('#credit-card-tax').val(responce.totaltax)

                if (responce.totaltax){
                    for (var productId in responce.taxPerItem){
                        $('div[id^=item-'+productId+']').find('.item-tax').text(responce.taxPerItem[productId])
                    }
                } else {
                    $('div[id^=item]').find('.item-tax').text('-')
                }

            }
        });
    };
    function loadStates(country) {
        var str = '';

        switch (country) {
            case 'US':
                var states = {
                    AK: "Alaska", AL: "Alabama", AR: "Arkansas", AZ: "Arizona",
                    CA: "California", CO: "Colorado", CT: "Connecticut",
                    DE: "Delaware", FL: "Florida", GA: "Georgia", HI: "Hawaii",
                    IA: "Iowa", ID: "Idaho", IL: "Illinois", IN: "Indiana",
                    KS: "Kansas", KY: "Kentucky", LA: "Louisiana", MA: "Massachusetts",
                    MD: "Maryland", ME: "Maine", MI: "Michigan", MN: "Minnesota",
                    MO: "Mississippi", MS: "Missouri", MT: "Montana", NC: "North Carolina",
                    ND: "North Dakota", NE: "Nebraska", NH: "New Hampshire", NJ: "New Jersey",
                    NM: "New Mexico", NV: "Nevada", NY: "New York", OH: "Ohio",
                    OK: "Oklahoma", OR: "Oregon", PA: "Pennsylvania", RI: "Rhode Island",
                    SC: "South Carolina", SD: "South Dakota", TN: "Tennessee", TX: "Texas",
                    UT: "Utah", VA: "Virginia", VT: "Vermont", WA: "Washington",
                    DC: "Washington D.C.", WI: "Wisconsin", WV: "West Virginia", WY: "Wyoming"
                }
                break;
            case 'CA':
                var states = {
                    Alberta: "Alberta",
                    'British Columbia': "British Columbia",
                    Manitoba: "Manitoba",
                    'New Brunswick': "New Brunswick",
                    Newfoundland: "Newfoundland",
                    'Northwest Territories': "Northwest Territories",
                    'Nova Scotia': "Nova Scotia",
                    Nunavut: "Nunavut",
                    Ontario: "Ontario",
                    'Prince Edward Island': "Prince Edward Island",
                    Quebec: "Quebec",
                    Saskatchewan: "Saskatchewan",
                    'Yukon Territory': "Yukon Territory"
                }
                break;
            default:
                var states = {}
                break;
        }
        for (var state in states){
            str += '<option value="'+state+'">'+states[state]+'</option>'
        }
        return str;
    }
</script>